
layui.config({
    base: '/js/user/' //扩展插件所在的目录
  }).extend({ //设定模块别名
    jquery_dotdotdot_min_js: 'layui.dotdotdot' //相对于上述 base 目录的子目录
  });

layui.use(['util', 'jquery', 'jquery_dotdotdot_min_js'], function () {
    var util = layui.util,
        $ = layui.jquery,
        jquery_dotdotdot_min_js = layui.jquery_dotdotdot_min_js;

    //Top header显示控制
    var is, timer, dom = $(document), fixedHeader = $('.jsFixedHeader');
    var scroll = function () {
        var stop = dom.scrollTop();
        if (stop >= 200) {
            is || (fixedHeader.show(), is = 1);
        } else {
            is && (fixedHeader.hide(), is = 0);
        }
    };
    dom.on('scroll', function () {
        clearTimeout(timer);
        timer = setTimeout(function () {
            scroll();
        }, 100);
    });

    $(document).ready(function () {
        clearTimeout(timer);
        timer = setTimeout(function () {
            scroll();
        }, 100);

        if($(".user_name").length){
            $(".user_name").dotdotdot({
                height: 20,
                fallbackToLetter: true,
                watch: true,
            });
        }
    });
    // 个人信息点击显示下拉

    $('.jsShowInfo').on('click', function (e) {
        // console.log(e);
        var _more = $(e.currentTarget).find('.we-more');
        var _child = $(e.currentTarget).siblings('.child');
        // console.log(_more);
        if (_more.hasClass('we-mored')) {
            _more.removeClass('we-mored');
            _child.hide();
            // console.log('show');
        } else {
            _more.addClass('we-mored');
            _child.show();
            // console.log('hide');
        }
    });

    
});

// 当网页向下滑动 20px 出现"返回顶部" 按钮
window.onscroll = function() {scrollFunction()};
 
function scrollFunction() {
    if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
        document.getElementById("myBtn").style.display = "block";
    } else {
        document.getElementById("myBtn").style.display = "none";
    }
}
 
// 点击按钮，返回顶部
function topFunction() {
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
}

//获取url后面的参数
function getQueryString(name, num) {
	var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
	var r = num ? decodeURI(window.location.search).substr(1).match(reg) : window.location.search.substr(1).match(reg);
	if(r != null) {
		return unescape(r[2]);
	}
	return null;
}


/**
 * 动态修改url多个参数
 * @param url 地址
 * @param obj 要变更的参数对象{arg:arg_val, arg1:arg_val1}
 */
function changeURLArgs(obj, url) {
    url = url ? url : this.location.href.toString();
    // console.log('url', url);
    // console.log('obj', obj);
    for (var arg in obj){
      var arg_val = obj[arg];
      var pattern = arg + '=([^&]*)';
      var replaceText = arg + '=' + arg_val;
      if (url.match(pattern)) {
        var tmp = '/(' + arg + '=)([^&]*)/gi';
        tmp = url.replace(eval(tmp), replaceText);
        url = tmp;
      } else {
        if (url.match('[\?]')) {
          var tmp = url + '&' + replaceText;
          url = tmp;
        } else {
          var tmp = url + '?' + replaceText;
          url = tmp;
        }
      }
    }
    // console.log('url', url);
    window.location.href = url;
    return url;
}